Trò chơi đua xe động vật trong UNITY Engine
114.923 lượt xem;
- Background.cs
- GameScreen /
- AnimalRacing /
- Scripts /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 namespace GamePlay
5 {
6 public class Background : MonoBehaviour
7 {
8 public GameObject bg0;
9 public GameObject bg1;
10 public GameObject bg2;
11
12 public void Start()
13 {
14 int world = Attr.currentWorld;
15
16 string[] mapnames = new string[] {"jungle","southpole","desert","volcano"};
17
18 int[] heights1 = new int[] {250, 332, 480, 218};
19 int[] heights2 = new int[] {125, 134, 304, 57};
20
21 bg0.GetComponent<BG>().setSprite(Resources.Load<Sprite>("Textures/Game/" + mapnames[world] + "/bg"), 0);
22 bg1.GetComponent<BG>().setSprite(Resources.Load<Sprite>("Textures/Game/" + mapnames[world] + "/bg1"), -240 + heights1[world]/2);
23 bg2.GetComponent<BG>().setSprite(Resources.Load<Sprite>("Textures/Game/" + mapnames[world] + "/bg2"), -240 + heights2[world]/2);
24 }
25
26 public void Update()
27 {
28 gameObject.transform.localPosition = new Vector3(Camera.main.transform.localPosition.x, Camera.main.transform.localPosition.y, gameObject.transform.localPosition.z);
29 }
30
31 public void setRuning(bool isRunning)
32 {
33 bg0.GetComponent<BG>().setRunning(isRunning);
34 bg1.GetComponent<BG>().setRunning(isRunning);
35 bg2.GetComponent<BG>().setRunning(isRunning);
36 }
37 }
38 }
2 using System.Collections;
3
4 namespace GamePlay
5 {
6 public class Background : MonoBehaviour
7 {
8 public GameObject bg0;
9 public GameObject bg1;
10 public GameObject bg2;
11
12 public void Start()
13 {
14 int world = Attr.currentWorld;
15
16 string[] mapnames = new string[] {"jungle","southpole","desert","volcano"};
17
18 int[] heights1 = new int[] {250, 332, 480, 218};
19 int[] heights2 = new int[] {125, 134, 304, 57};
20
21 bg0.GetComponent<BG>().setSprite(Resources.Load<Sprite>("Textures/Game/" + mapnames[world] + "/bg"), 0);
22 bg1.GetComponent<BG>().setSprite(Resources.Load<Sprite>("Textures/Game/" + mapnames[world] + "/bg1"), -240 + heights1[world]/2);
23 bg2.GetComponent<BG>().setSprite(Resources.Load<Sprite>("Textures/Game/" + mapnames[world] + "/bg2"), -240 + heights2[world]/2);
24 }
25
26 public void Update()
27 {
28 gameObject.transform.localPosition = new Vector3(Camera.main.transform.localPosition.x, Camera.main.transform.localPosition.y, gameObject.transform.localPosition.z);
29 }
30
31 public void setRuning(bool isRunning)
32 {
33 bg0.GetComponent<BG>().setRunning(isRunning);
34 bg1.GetComponent<BG>().setRunning(isRunning);
35 bg2.GetComponent<BG>().setRunning(isRunning);
36 }
37 }
38 }